/*
 
 tabBar 是在  tabBarController 中的属性
 
 */

import UIKit

class HYFTabBarController: UITabBarController {
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //创建 一个 tabBar 属性
        let tabBar = HYFTabBar()
        
        tabBar.closure = { [weak self] in
            
            let componseView = HYFComposeView()
        
            componseView.composeViewShow(self!)
            
            
//            let componseVc = HYFComposeController()
// 
//            self?.presentViewController( UINavigationController(rootViewController: componseVc), animated: true, completion: nil)
        }
        
        //通过 kvc 将自定义的 tabBar 赋值给 系统的 tabBar
        setValue(tabBar, forKey: "tabBar")
        
        //添加的是对象,需要加小括号!
       addChildControllers(HYFHomeController(), title: "首页", imgName: "tabbar_home")
        
       addChildControllers(HYFMessageController(), title: "信息", imgName: "tabbar_message_center")
        
       addChildControllers(HYFDiscoverController(), title: "发现", imgName: "tabbar_discover")
        
       addChildControllers(HYFProfileController(), title: "我", imgName: "tabbar_profile")
        
    }

    func addChildControllers(vc:UIViewController,title:String,imgName:String){
        
        //设置标题
       vc.title = title
        //设置图片
       vc.tabBarItem.image = UIImage(named:imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中图片
       vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //设置根控制器
       addChildViewController(UINavigationController(rootViewController: vc))
    }
}
